********Figure E.1********


*Load data
cd "$reploc/data/created_data"
use indo_full, clear


*Do these results for primary sample
sort pidlink ifls
foreach var of varlist rbuc_garefined rbuc grbrprovAvg_lam0co3 grbrprovSD_lam0co3 inflation{
gen `var'dif=`var'-`var'[_n-1] if ifls==5 & pidlink==pidlink[_n-1]
} 

egen coh_prov_clust=group(biryear_impl birprov_impl)

gen primarysample1=0
replace primarysample1=1 if rbuc_garefineddif!=. & grbrprovAvg_lam0co3dif!=. & grbrprovSD_lam0co3dif!=. & inflationdif!=. &  biryear_impl>=1961 & coh_prov_clust!=.

egen primarysample=total(primarysample1), by(pidlink)

drop if ifls==.
keep if panel==1
keep if primarysample==1

*Add how many people per birth province
keep if ifls==5
gen popi=1
collapse (sum) popi, by(birprov_impl)

rename birprov_impl prov_id
tempfile bprovpops
save "`bprovpops'", replace

cd "$reploc/data/shpfiles"
shp2dta using IDN_adm1, database(indodb) coordinates(indocoord) genid(id) gencentroids(cent) replace


use indodb.dta, clear

*Change to province id
generate var11 = 11 in 1
replace var11 = 51 in 2
replace var11 = 19 in 3
replace var11 = 36 in 4
replace var11 = 17 in 5
replace var11 = 31 in 6
replace var11 = . in 7
replace var11 = . in 6
replace var11 = 31 in 7
replace var11 = 15 in 8
replace var11 = . in 7
replace var11 = . in 8
replace var11 = 31 in 8
replace var11 = 15 in 9
replace var11 = 75 in 6
replace var11 = 32 in 10
replace var11 = 33 in 11
replace var11 = 34 in 12
replace var11 = 35 in 12
replace var11 = 61 in 13
replace var11 = 63 in 14
replace var11 = 62 in 15
replace var11 = 64 in 16
replace var11 = 65 in 17
replace var11 = 51 in 18
replace var11 = 21 in 18
replace var11 = 18 in 19
replace var11 = 81 in 21
replace var11 = 97 in 20
replace var11 = 97 in 21
replace var11 = 82 in 20
replace var11 = 81 in 21
replace var11 = 52 in 22
replace var11 = 53 in 23
replace var11 = 94 in 24
replace var11 = 91 in 25
replace var11 = 14 in 26
replace var11 = 14 in 25
replace var11 = 76 in 26
replace var11 = 73 in 27
replace var11 = 72 in 28
replace var11 = 74 in 29
replace var11 = 71 in 30
replace var11 = 13 in 31
replace var11 = 16 in 32
replace var11 = 12 in 33
replace var11 = 34 in 34
replace var11 = 91 in 7

rename var11 prov_id

merge 1:1 prov_id using "`bprovpops'"
tostring popi, gen(popstring_lb) 
sum popi, d
local maxi=r(max)

*Adjusting where population number appears on map
replace x_cent=x_cent+0.32 if prov_id==13
replace x_cent=x_cent+0.15 if prov_id==17
replace x_cent=x_cent+0.3 if prov_id==31 
replace y_cent=y_cent+0.5 if prov_id==31
replace x_cent=x_cent-0.3 if prov_id==35
replace y_cent=y_cent+0.6 if prov_id==51
replace y_cent=y_cent-0.7 if prov_id==52
replace x_cent=x_cent-0.2 if prov_id==73
replace y_cent=y_cent-0.4 if prov_id==72
replace x_cent=x_cent+0.4 if prov_id==72
replace y_cent=y_cent-0.45 if prov_id==71
replace x_cent=x_cent-0.2 if prov_id==71
replace y_cent=y_cent-0.45 if prov_id==71
replace x_cent=x_cent-0.2 if prov_id==71
replace y_cent=y_cent-0.42 if prov_id==34
replace x_cent=x_cent-0.05 if prov_id==34

cd "$reploc/data/shpfiles"
spmap popi using indocoord if popi>0, id(id) fcolor(BrBG)  label(xcoord(x_cent) ycoord(y_cent) label(popstring_lb) color(blue) size(*0.9)) clmethod(custom) clbreaks(0 135 `maxi')  legend(label(1 "No Data") label(2 "Other Birth Provinces") label(3 "IFLS Provinces"))


cd "$reploc/results"
graph export FigureE1.eps, replace







